using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using OpenTK.Math;
using Dogfight2008.Common;

namespace Dogfight2008.Tests
{
  /*
   * #A shot should have Box2d for collision detection, at
   * #least be able to produce one on demand.
   * #It should accept Tick().
   * #It should be initialized using centre, direction and
   * #speed (m/s).
   * #It should be pure 2d; so I cannot put rendering inside
   * #it. Instead it should make position, direction accessible
   * #to clients, so they can render it.
   */
  [TestFixture]
  public class ShotFixture
  {
    [Test]
    public void Construct()
    {
      Shot shot = new Shot(new Vector2(0, 0), Calc.DegreesToRadians(45), 10, 0);
    }

    [Test]
    public void Accessors()
    {
      Shot shot = new Shot(new Vector2(0, 1), 2, 3, 0);
      Assert.AreEqual(0, shot.Position.X);
      Assert.AreEqual(1, shot.Position.Y);
      Assert.AreEqual(2, shot.Angle);
      Assert.AreEqual(3, shot.Speed);
    }

    [Test]
    public void Tick()
    {
      double angle = Calc.DegreesToRadians(45);
      Shot shot = new Shot(new Vector2(0, 1), angle, 1, 0);
      shot.Tick(1);
      Vector2 exp = Calc.v(Math.Cos(angle), 1+Math.Sin(angle));
      Assert.AreEqual(exp.X, shot.Position.X);
      Assert.AreEqual(exp.Y, shot.Position.Y);
    }

    [Test]
    public void GetBox2d()
    {
      double speed = 1; // 1 m / ms
      double deltaMS = 10;
      double explength = speed * deltaMS;
      Box2d expected = new Box2d(10 + explength, 20, 0, explength, -0.01, 0.01, 0);
      Shot shot = new Shot(Calc.v(10, 20), 0, speed, 0);
      shot.Tick(deltaMS);
      Box2d result = shot.GetBox2d();
      Assert.AreEqual(expected, result);
    }
  }
}
